{% load i18n %}
{% load debug_toolbar_utils %}
<div class="clearfix">
	<ul class="stats">
		{% for alias, info in databases %}
			<li>
				<strong class="label"><span style="background-color: rgb({{ info.rgb_color|join:", " }})" class="color">&nbsp;</span> {{ alias }}</strong>
				<span class="info">{{ info.time_spent|floatformat:"2" }} ms ({% blocktrans count info.num_queries as num %}{{ num }} query{% plural %}{{ num }} queries{% endblocktrans %})</span>
			</li>
		{% endfor %}
	</ul>
</div>

{% if queries %}
	<table>
		<thead>
			<tr>
				<th class="color">&nbsp;</th>
				<th class="query" colspan="2">{% trans 'Query' %}</th>
				<th class="timeline">{% trans 'Timeline' %}</th>
				<th class="time">{% trans 'Time (ms)' %}</th>
				<th class="actions">{% trans "Action" %}</th>
			</tr>
		</thead>
		<tbody>
			{% for query in queries %}
				<tr class="djDebugHoverable {% cycle 'djDebugOdd' 'djDebugEven' %}{% if query.is_slow %} djDebugRowWarning{% endif %}{% if query.starts_trans %} djDebugStartTransaction{% endif %}{% if query.ends_trans %} djDebugEndTransaction{% endif %}{% if query.in_trans %} djDebugInTransaction{% endif %}" id="sqlMain_{{ forloop.counter }}">
					<td class="color"><span style="background-color: rgb({{ query.rgb_color|join:", " }});">&nbsp;</span></td>
					<td class="toggle">
						<a class="djToggleSwitch" data-toggle-name="sqlMain" data-toggle-id="{{ forloop.counter }}" data-toggle-open="+" data-toggle-close="-" href="javascript:void(0)">+</a>
					</td>
					<td class="query">
						<div class="djDebugSqlWrap">
							<div class="djDebugSql">{{ query.sql|safe }}</div>
						</div>
					</td>
					<td class="timeline">
						<div class="djDebugTimeline"><div class="djDebugLineChart{% if query.is_slow %} djDebugLineChartWarning{% endif %}" style="left:{{ query.start_offset|dotted_number }}%;"><strong style="width:{{ query.width_ratio_relative|dotted_number }}%;">{{ query.width_ratio }}%</strong></div></div>
					</td>
					<td class="time">
						{{ query.duration|floatformat:"2" }}
					</td>
					<td class="actions">

					{% if query.params %}
						{% if query.is_select %}
							<form method="post">
								{{ query.form }}

								<button formaction="/__debug__/sql_select/" class="remoteCall">Sel</button>
								<button formaction="/__debug__/sql_explain/" class="remoteCall">Expl</button>

								{% ifequal query.engine 'mysql' %}
									<button formaction="/__debug__/sql_profile/" class="remoteCall">Prof</button>
								{% endifequal %}
							</form>
						{% endif %}
					{% endif %}
					</td>
				</tr>
				<tr class="djUnselected djDebugHoverable {% cycle 'djDebugOdd' 'djDebugEven' %}{% if query.is_slow %} djDebugRowWarning{% endif %} djToggleDetails_{{ forloop.counter }}" id="sqlDetails_{{ forloop.counter }}">
					<td colspan="2"></td>
					<td colspan="4">
						<div class="djSQLDetailsDiv">
							<p><strong>{% trans "Connection:" %}</strong> {{ query.alias }}</p>
							{% if query.iso_level %}
								<p><strong>{% trans "Isolation level:" %}</strong> {{ query.iso_level }}</p>
							{% endif %}
							{% if query.trans_status %}
								<p><strong>{% trans "Transaction status:" %}</strong> {{ query.trans_status }}</p>
							{% endif %}
							{% if query.stacktrace %}
								<pre class="stack">{{ query.stacktrace }}</pre>
							{% endif %}
							{% if query.template_info %}
								<table>
									{% for line in query.template_info.context %}
									<tr>
										<td>{{ line.num }}</td>
										<td><code style="font-family: monospace;{% if line.highlight %}background-color: lightgrey{% endif %}">{{ line.content }}</code></td>
									</tr>
									{% endfor %}
								</table>
								<p><strong>{{ query.template_info.name|default:_("(unknown)") }}</strong></p>
							{% endif %}
						</div>
					</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>
{% else %}
	<p>{% trans "No SQL queries were recorded during this request." %}</p>
{% endif %}
